package com.sline.thread;

public class Demo1_Thread {
    public static void main(String[] args) {
        // demo1();

        // demo2();

        MyRunable mr = new MyRunable();
        Thread thread = new Thread(mr);
        thread.start();

        for (int i = 0; i < 100000; i++) {
            System.out.println("我是主线程");
        }
    }

    private static void demo2() {
        MyThread mt = new MyThread();
        mt.start();

        for (int i = 0; i < 100000; i++) {
            System.out.println("我是主线程");
        }
    }

    private static void demo1() {
        for (int i = 0; i < 1000000; i++) {
            new Demo();
        }

        for (int i = 0; i < 10000; i++) {
            System.out.println("我是主线程");
        }
    }
}

class Demo {
    @Override
    public void finalize() {
        System.out.println("垃圾被清扫了~");
    }
}

class MyThread extends Thread {
    public void run() {
        for (int i = 0; i < 100000; i++) {
            System.out.println("MyThread");
        }
    }
}

class MyRunable implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 100000; i++) {
            System.out.println("MyRunable");
        }
    }
}